Introduction

There are a series of Submeters that meassure the energy consumption in different parts of an appartment. These meassurements will be used to forecast consumption on the next year, but above all there will be an exploration that will be made to give recommendations to the tenant of the building on how to save energy and why these devices can help reduce the energy consumption.

Used Libraries

library(RMySQL)     #for the SQL queries
library(DBI)        #necessary for the RMySQL library
library(ggplot2)    #graph library
library(plotly)     #this one is better for the line graphs
library(knitr)      #for the tables aes
library(magrittr)   #magic %>% 
library(dplyr)      #data wrangling
library(lubridate)  #convert date and time
library(grid)       #formating the ggplot graphics
library(ggfortify)  #ploting TS object
library(forecast)   #for forecasting

Fetch Data and Select Variables

#Importing the data, create a database connection

con <- dbConnect(MySQL(),
                 user = 'deepAnalytics',
                 password = 'Sqltask1234!',
                 dbname = 'dataanalytics2018',
                 host = 'data-analytics-2018.cbrosir2cswx.us-east-1.rds.amazonaws.com')

#List the tables contained in the database 

dbListTables(con)

output

## [1] "iris"    "yr_2006" "yr_2007" "yr_2008" "yr_2009" "yr_2010"
#quick check of attributes listed in one of the lists, I kow beforehand they all, except one, contain the same attributes

dbListFields(con, 'yr_2006')

output

##  [1] "id"                    "Date"                  "Time"                 
##  [4] "Global_active_power"   "Global_reactive_power" "Global_intensity"     
##  [7] "Voltage"               "Sub_metering_1"        "Sub_metering_2"       
## [10] "Sub_metering_3"
#save all df locally with all the info in them

yr2006_local <- dbGetQuery(con, "SELECT * FROM yr_2006")
write.csv(yr2006_local, file = "Data/yr2006_local")

yr2007_local <- dbGetQuery(con, "SELECT * FROM yr_2007")
write.csv(yr2007_local, file = "Data/yr2007_local")

yr2008_local <- dbGetQuery(con, "SELECT * FROM yr_2008")
write.csv(yr2008_local, file = "Data/yr2008_local")

yr2009_local <- dbGetQuery(con, "SELECT * FROM yr_2009")
write.csv(yr2009_local, file = "Data/yr2009_local")

yr2010_local <- dbGetQuery(con, "SELECT * FROM yr_2010")
write.csv(yr2010_local, file = "Data/yr2010_local")

#for the analysis I need to implement, only 5 attributes are relevant, Time, Date, Global_active_power and the 3 Sub_metering

yr_2006 <- select(yr2006_local, Date, Time, Sub_metering_1, Sub_metering_2, Sub_metering_3, Global_active_power)
  
yr_2007 <- select(yr2007_local, Date, Time, Sub_metering_1, Sub_metering_2, Sub_metering_3, Global_active_power)

yr_2008 <- select(yr2008_local, Date, Time, Sub_metering_1, Sub_metering_2, Sub_metering_3, Global_active_power)

yr_2009 <- select(yr2009_local, Date, Time, Sub_metering_1, Sub_metering_2, Sub_metering_3, Global_active_power)
  
yr_2010 <- select(yr2010_local, Date, Time, Sub_metering_1, Sub_metering_2, Sub_metering_3, Global_active_power)
#str() visualized as kable table

x_str <- function(data){
 data.frame(
            variable = names(data),
            class = sapply(data, typeof),
            first_values = sapply(data, function(x) paste0(head(x), collapse = ", ")),
            row.names = NULL) %>%
            kable()
}

Exploration of the Data

Year 2006

x_str(yr_2006)
variable class first_values
Date character 2006-12-16, 2006-12-16, 2006-12-16, 2006-12-16, 2006-12-16, 2006-12-16
Time character 17:24:00, 17:25:00, 17:26:00, 17:27:00, 17:28:00, 17:29:00
Sub_metering_1 double 0, 0, 0, 0, 0, 0
Sub_metering_2 double 1, 1, 2, 1, 1, 2
Sub_metering_3 double 17, 16, 17, 17, 17, 17
Global_active_power double 4.216, 5.36, 5.374, 5.388, 3.666, 3.52
kable(summary(yr_2006))
Date Time Sub_metering_1 Sub_metering_2 Sub_metering_3 Global_active_power
Length:21992 Length:21992 Min. : 0.000 Min. : 0.000 Min. : 0.00 Min. :0.194
Class :character Class :character 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.00 1st Qu.:0.496
Mode :character Mode :character Median : 0.000 Median : 0.000 Median : 0.00 Median :1.708
NA NA Mean : 1.249 Mean : 2.215 Mean : 7.41 Mean :1.901
NA NA 3rd Qu.: 0.000 3rd Qu.: 1.000 3rd Qu.:17.00 3rd Qu.:2.692
NA NA Max. :77.000 Max. :74.000 Max. :20.00 Max. :9.132
kable(head(yr_2006))
Date Time Sub_metering_1 Sub_metering_2 Sub_metering_3 Global_active_power
2006-12-16 17:24:00 0 1 17 4.216
2006-12-16 17:25:00 0 1 16 5.360
2006-12-16 17:26:00 0 2 17 5.374
2006-12-16 17:27:00 0 1 17 5.388
2006-12-16 17:28:00 0 1 17 3.666
2006-12-16 17:29:00 0 2 17 3.520

Year 2007

x_str(yr_2007)
variable class first_values
Date character 2007-01-01, 2007-01-01, 2007-01-01, 2007-01-01, 2007-01-01, 2007-01-01
Time character 00:00:00, 00:01:00, 00:02:00, 00:03:00, 00:04:00, 00:05:00
Sub_metering_1 double 0, 0, 0, 0, 0, 0
Sub_metering_2 double 0, 0, 0, 0, 0, 0
Sub_metering_3 double 0, 0, 0, 0, 0, 0
Global_active_power double 2.58, 2.552, 2.55, 2.55, 2.554, 2.55
kable(summary(yr_2007))
Date Time Sub_metering_1 Sub_metering_2 Sub_metering_3 Global_active_power
Length:521669 Length:521669 Min. : 0.000 Min. : 0.000 Min. : 0.000 Min. : 0.082
Class :character Class :character 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.278
Mode :character Mode :character Median : 0.000 Median : 0.000 Median : 0.000 Median : 0.504
NA NA Mean : 1.232 Mean : 1.638 Mean : 5.795 Mean : 1.117
NA NA 3rd Qu.: 0.000 3rd Qu.: 1.000 3rd Qu.:17.000 3rd Qu.: 1.548
NA NA Max. :78.000 Max. :78.000 Max. :20.000 Max. :10.670
kable(head(yr_2007))
Date Time Sub_metering_1 Sub_metering_2 Sub_metering_3 Global_active_power
2007-01-01 00:00:00 0 0 0 2.580
2007-01-01 00:01:00 0 0 0 2.552
2007-01-01 00:02:00 0 0 0 2.550
2007-01-01 00:03:00 0 0 0 2.550
2007-01-01 00:04:00 0 0 0 2.554
2007-01-01 00:05:00 0 0 0 2.550

Year 2008

x_str(yr_2008)
variable class first_values
Date character 2008-01-01, 2008-01-01, 2008-01-01, 2008-01-01, 2008-01-01, 2008-01-01
Time character 00:00:00, 00:01:00, 00:02:00, 00:03:00, 00:04:00, 00:05:00
Sub_metering_1 double 0, 0, 0, 0, 0, 0
Sub_metering_2 double 0, 0, 0, 0, 0, 0
Sub_metering_3 double 18, 18, 18, 18, 18, 17
Global_active_power double 1.62, 1.626, 1.622, 1.612, 1.612, 1.546
kable(summary(yr_2008))
Date Time Sub_metering_1 Sub_metering_2 Sub_metering_3 Global_active_power
Length:526905 Length:526905 Min. : 0.00 Min. : 0.000 Min. : 0.000 Min. : 0.076
Class :character Class :character 1st Qu.: 0.00 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.300
Mode :character Mode :character Median : 0.00 Median : 0.000 Median : 1.000 Median : 0.566
NA NA Mean : 1.11 Mean : 1.256 Mean : 6.034 Mean : 1.072
NA NA 3rd Qu.: 0.00 3rd Qu.: 1.000 3rd Qu.:17.000 3rd Qu.: 1.518
NA NA Max. :80.00 Max. :76.000 Max. :31.000 Max. :10.348
kable(head(yr_2008))
Date Time Sub_metering_1 Sub_metering_2 Sub_metering_3 Global_active_power
2008-01-01 00:00:00 0 0 18 1.620
2008-01-01 00:01:00 0 0 18 1.626
2008-01-01 00:02:00 0 0 18 1.622
2008-01-01 00:03:00 0 0 18 1.612
2008-01-01 00:04:00 0 0 18 1.612
2008-01-01 00:05:00 0 0 17 1.546

Year 2009

x_str(yr_2009)
variable class first_values
Date character 2009-01-01, 2009-01-01, 2009-01-01, 2009-01-01, 2009-01-01, 2009-01-01
Time character 00:00:00, 00:01:00, 00:02:00, 00:03:00, 00:04:00, 00:05:00
Sub_metering_1 double 0, 0, 0, 0, 0, 0
Sub_metering_2 double 0, 0, 0, 0, 0, 0
Sub_metering_3 double 0, 0, 0, 0, 0, 0
Global_active_power double 0.484, 0.484, 0.482, 0.482, 0.482, 0.57
kable(summary(yr_2009))
Date Time Sub_metering_1 Sub_metering_2 Sub_metering_3 Global_active_power
Length:521320 Length:521320 Min. : 0.000 Min. : 0.000 Min. : 0.000 Min. : 0.122
Class :character Class :character 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.000 1st Qu.: 0.318
Mode :character Mode :character Median : 0.000 Median : 0.000 Median : 1.000 Median : 0.622
NA NA Mean : 1.137 Mean : 1.136 Mean : 6.823 Mean : 1.079
NA NA 3rd Qu.: 0.000 3rd Qu.: 1.000 3rd Qu.:18.000 3rd Qu.: 1.514
NA NA Max. :82.000 Max. :77.000 Max. :31.000 Max. :11.122
kable(head(yr_2009))
Date Time Sub_metering_1 Sub_metering_2 Sub_metering_3 Global_active_power
2009-01-01 00:00:00 0 0 0 0.484
2009-01-01 00:01:00 0 0 0 0.484
2009-01-01 00:02:00 0 0 0 0.482
2009-01-01 00:03:00 0 0 0 0.482
2009-01-01 00:04:00 0 0 0 0.482
2009-01-01 00:05:00 0 0 0 0.570

Year 2010

x_str(yr_2010)
variable class first_values
Date character 2010-01-01, 2010-01-01, 2010-01-01, 2010-01-01, 2010-01-01, 2010-01-01
Time character 00:00:00, 00:01:00, 00:02:00, 00:03:00, 00:04:00, 00:05:00
Sub_metering_1 double 0, 0, 0, 0, 0, 0
Sub_metering_2 double 0, 0, 0, 0, 0, 0
Sub_metering_3 double 18, 18, 19, 18, 18, 19
Global_active_power double 1.79, 1.78, 1.78, 1.746, 1.686, 1.686
kable(summary(yr_2010))
Date Time Sub_metering_1 Sub_metering_2 Sub_metering_3 Global_active_power
Length:457394 Length:457394 Min. : 0.0000 Min. : 0.000 Min. : 0.000 Min. :0.138
Class :character Class :character 1st Qu.: 0.0000 1st Qu.: 0.000 1st Qu.: 1.000 1st Qu.:0.336
Mode :character Mode :character Median : 0.0000 Median : 0.000 Median : 1.000 Median :0.700
NA NA Mean : 0.9875 Mean : 1.102 Mean : 7.244 Mean :1.061
NA NA 3rd Qu.: 0.0000 3rd Qu.: 1.000 3rd Qu.:18.000 3rd Qu.:1.512
NA NA Max. :88.0000 Max. :80.000 Max. :31.000 Max. :9.724
kable(head(yr_2010))
Date Time Sub_metering_1 Sub_metering_2 Sub_metering_3 Global_active_power
2010-01-01 00:00:00 0 0 18 1.790
2010-01-01 00:01:00 0 0 18 1.780
2010-01-01 00:02:00 0 0 19 1.780
2010-01-01 00:03:00 0 0 18 1.746
2010-01-01 00:04:00 0 0 18 1.686
2010-01-01 00:05:00 0 0 19 1.686

Data Manipulation

#join the df that are complete and will be used for the analysis

yr_07_08_09 <- bind_rows(yr_2007, yr_2008, yr_2009)

#change the names of the columns

names(yr_07_08_09)[names(yr_07_08_09) == "Sub_metering_1"] <- "Kitchen"
names(yr_07_08_09)[names(yr_07_08_09) == "Sub_metering_2"] <- "Laundry_room"
names(yr_07_08_09)[names(yr_07_08_09) == "Sub_metering_3"] <- "Water_heater"

#changing the submeters to kw/h

yr_07_08_09$Kitchen <- yr_07_08_09$Kitchen/1000
yr_07_08_09$Laundry_room <- yr_07_08_09$Laundry_room/1000
yr_07_08_09$Water_heater <- yr_07_08_09$Water_heater/1000
kable(head(yr_07_08_09, n = 5))
Date Time Kitchen Laundry_room Water_heater Global_active_power
2007-01-01 00:00:00 0 0 0 2.580
2007-01-01 00:01:00 0 0 0 2.552
2007-01-01 00:02:00 0 0 0 2.550
2007-01-01 00:03:00 0 0 0 2.550
2007-01-01 00:04:00 0 0 0 2.554
#change the reading to the same unit in the "Global_active_power" to kw/h, and take from the reading the sum of the other three sub meters

yr_07_08_09$Rest_house <- round(yr_07_08_09$Global_active_power/60 - (yr_07_08_09$Kitchen + yr_07_08_09$Laundry_room + yr_07_08_09$Water_heater), 3)
kable(head(yr_07_08_09))
Date Time Kitchen Laundry_room Water_heater Global_active_power Rest_house
2007-01-01 00:00:00 0 0 0 2.580 0.043
2007-01-01 00:01:00 0 0 0 2.552 0.043
2007-01-01 00:02:00 0 0 0 2.550 0.042
2007-01-01 00:03:00 0 0 0 2.550 0.042
2007-01-01 00:04:00 0 0 0 2.554 0.043
2007-01-01 00:05:00 0 0 0 2.550 0.042
#combine date and time attributes in a new column

yr_07_08_09$Date_time <- paste(yr_07_08_09$Date, yr_07_08_09$Time)

#moving the column

yr_07_08_09 <- yr_07_08_09[,c(ncol(yr_07_08_09), 1:(ncol(yr_07_08_09)-1))]

Creation of New Variables Based on Date_time

#convert Date_time to POSIXct

yr_07_08_09$Date_time <- ymd_hms(yr_07_08_09$Date_time)
yr_07_08_09$Time <- hms(yr_07_08_09$Time)
yr_07_08_09$Date <- ymd(yr_07_08_09$Date)

#add the time zone

attr(yr_07_08_09$Date_time, "tzone") <- "Europe/Paris"

## Inspect the data types

x_str(yr_07_08_09)
variable class first_values
Date_time double 2007-01-01 01:00:00, 2007-01-01 01:01:00, 2007-01-01 01:02:00, 2007-01-01 01:03:00, 2007-01-01 01:04:00, 2007-01-01 01:05:00
Date double 2007-01-01, 2007-01-01, 2007-01-01, 2007-01-01, 2007-01-01, 2007-01-01
Time double 0S, 1M 0S, 2M 0S, 3M 0S, 4M 0S, 5M 0S
Kitchen double 0, 0, 0, 0, 0, 0
Laundry_room double 0, 0, 0, 0, 0, 0
Water_heater double 0, 0, 0, 0, 0, 0
Global_active_power double 2.58, 2.552, 2.55, 2.55, 2.554, 2.55
Rest_house double 0.043, 0.043, 0.042, 0.042, 0.043, 0.042
#create new columns for information mining

yr_07_08_09$Year      <- year(yr_07_08_09$Date_time)
yr_07_08_09$Quarter   <- quarter(yr_07_08_09$Date_time)
yr_07_08_09$Weekday   <- wday(yr_07_08_09$Date_time)
yr_07_08_09$Minute    <- minute(yr_07_08_09$Date_time)
yr_07_08_09$Month     <- month(yr_07_08_09$Date_time)
yr_07_08_09$Day       <- day(yr_07_08_09$Date_time)
yr_07_08_09$Hour      <- hour(yr_07_08_09$Date_time)
#checking how much energy each submeter used in 2008 during the weekend and workdays

submeters_consumption_08 <- yr_07_08_09 %>%
                             filter(Year == 2008, Weekday == 1 & 2 & 3 & 4 & 5) %>%
                             select(Kitchen, Laundry_room, Water_heater, Rest_house) %>% 
                             summarise_all(funs(sum)) %>% 
                             tidyr::gather(key = Area, value = KwH) %>% 
                             mutate(Porcentage = round(KwH/sum(KwH) * 100, 2))

#pie chart showing the porcentage of power used by each submeter in 2008

ggplot(submeters_consumption_08, aes(x = "", y = KwH, fill = Area)) +
  geom_bar(width = 1, stat = "identity") +
  coord_polar("y", start = 0) +
  scale_fill_brewer(palette = "Dark2") +
  blank_theme +   #Previously created object, refer to RMD doc to see it
  theme(axis.text.x = element_blank()) +
#  theme(plot.margin = unit(c(0, -10, -10, -30), "mm")) +
  geom_text(aes(label = Porcentage), position = position_stack(vjust = 0.5)) +
  ggtitle("Sum of the Energy Consumption During all Weekdays in 2008")

#checking how much energy each submeter used during the sum of the weekends of the year

submeters_consumption_weekends <- yr_07_08_09 %>%
                                   filter(Weekday == 6 & 7) %>%
                                   select(Kitchen, Laundry_room, Water_heater, Rest_house) %>% 
                                   summarise_all(funs(sum)) %>% 
                                   tidyr::gather(key = Area, value = KwH) %>% 
                                   mutate(Porcentage = round(KwH/sum(KwH) * 100, 2))

#pie chart showing the porcentage of power used by each submeter in 2008

ggplot(submeters_consumption_weekends, aes(x = "", y = KwH, fill = Area)) +
  geom_bar(width = 1, stat = "identity") +
  coord_polar("y", start = 0) +
  scale_fill_brewer(palette = "Dark2") +
  blank_theme +   #Previously created object, refer to RMD doc to see it
  theme(axis.text.x = element_blank()) +
#  theme(plot.margin = unit(c(0, -10, -10, -30), "mm")) +
  geom_text(aes(label = Porcentage), position = position_stack(vjust = 0.5)) +
  ggtitle("Sum of the Energy Consumption During All Weekends in 2008")

#Note to self: quite the jump in hot water ussage during the weekends. People are more at home, that´d explain it.
#overall ussage of energy is 6 times higher on the weekends than on the weekdays

Inspection Patterns of Consumption in Time

DAY

#plot of the mid summer week, friday 2009

Fri_summer <- yr_07_08_09 %>% 
                      filter(Year == 2009 & Month == 6 & Day == 26 & (Minute == 0 | Minute == 10 | Minute == 20 | Minute == 30 | Minute == 40 | Minute == 50))

plot_ly(Fri_summer, x = ~Date_time, y = ~Kitchen, name = 'Kitchen', type = 'scatter', mode = 'lines') %>%
  add_trace(y = ~Laundry_room, mode = 'lines') %>%
  add_trace(y = ~Water_heater, mode = 'lines') %>%
  add_trace(y = ~Rest_house, mode = 'lines') %>%
  layout(title = "Energy Consumption Mid-Summer Friday 26th of June 2009",
         xaxis = list(title = "Time"),
         yaxis = list (title = "KwH"))

WEEK

#plot of the mid summer week of 2009

Fri_summer <- yr_07_08_09 %>% 
                  filter(Date_time > "2009-06-22" & Date_time < "2009-06-28" & (Hour == 1 | Hour == 2 | Hour == 3 | Hour == 4 | Hour == 5 | Hour                          == 6 | Hour == 7 | Hour == 8 | Hour == 9 | Hour == 10 | Hour == 11 | Hour == 12 | Hour == 13 | Hour == 14 | Hour == 15                          | Hour == 16 | Hour == 17 | Hour == 18 | Hour == 19 | Hour == 20 | Hour == 21 |Hour == 22 | Hour == 23 | Hour == 0))

plot_ly(Fri_summer, x = ~Date_time, y = ~Kitchen, name = 'Kitchen', type = 'scatter', mode = 'lines') %>%
  add_trace(y = ~Laundry_room, mode = 'lines') %>%
  add_trace(y = ~Water_heater, mode = 'lines') %>%
  add_trace(y = ~Rest_house, mode = 'lines') %>%
  layout(title = "Energy Consumption Mid-Summer Week 2009",
         xaxis = list(title = "Time"),
         yaxis = list (title = "KwH"))

MONTH

#plot of the mid summer week of 2009

Jul_2009 <- yr_07_08_09 %>% 
                  filter(Year == 2009 & Month == 7 & (Hour == 1 | Hour == 2 | Hour == 3 | Hour == 4 | Hour == 5 | Hour == 6 | Hour == 7 | Hour                            == 8 | Hour == 9 | Hour == 10 | Hour == 11 | Hour == 12 | Hour == 13 | Hour == 14 | Hour == 15 | Hour == 16 | Hour ==                           17 | Hour == 18 | Hour == 19 | Hour == 20 | Hour == 21 |Hour == 22 | Hour == 23 | Hour == 0))

plot_ly(Jul_2009, x = ~Date_time, y = ~Kitchen, name = 'Kitchen', type = 'scatter', mode = 'lines') %>%
  add_trace(y = ~Laundry_room, mode = 'lines') %>%
  add_trace(y = ~Water_heater, mode = 'lines') %>%
  add_trace(y = ~Rest_house, mode = 'lines') %>%
  layout(title = "Energy Consumption June 2009",
         xaxis = list(title = "Time"),
         yaxis = list (title = "KwH"))

Forecasting on Each Submeter

KITCHEN

#subset to one observation per day on 

weekly_07_09 <- filter(yr_07_08_09, Weekday == 1 & 
                              Hour == 20 & Minute == 1)

#TS object with submeter from Kitchen

tsKitchen <- ts(weekly_07_09$Kitchen, frequency=52, start = c(2007, 1))

#ploting submeter Kitchen with autoplot - add labels, color

autoplot(tsKitchen, ts.colour = 'red', xlab = "Time", ylab = "KwH", main = "Kitchen")

#trying other plotting package

plot.ts(tsKitchen)

#linear model
fitKitchen <- tslm(tsKitchen ~ trend + season) 
summary(fitKitchen)

output

## 
## Call:
## tslm(formula = tsKitchen ~ trend + season)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.026024 -0.001357  0.000000  0.001357  0.027357 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  1.716e-03  5.816e-03   0.295  0.76855   
## trend       -2.609e-05  1.913e-05  -1.364  0.17553   
## season2      2.609e-05  8.100e-03   0.003  0.99744   
## season3      1.172e-02  8.100e-03   1.447  0.15107   
## season4      2.441e-02  8.100e-03   3.014  0.00327 **
## season5      1.044e-04  8.100e-03   0.013  0.98975   
## season6      1.305e-04  8.100e-03   0.016  0.98718   
## season7      4.899e-04  8.100e-03   0.060  0.95190   
## season8     -1.507e-04  8.101e-03  -0.019  0.98520   
## season9      1.875e-03  8.101e-03   0.232  0.81740   
## season10     1.257e-02  8.101e-03   1.551  0.12398   
## season11     1.226e-02  8.102e-03   1.513  0.13335   
## season12    -4.632e-05  8.102e-03  -0.006  0.99545   
## season13     1.298e-02  8.103e-03   1.602  0.11234   
## season14     5.863e-06  8.103e-03   0.001  0.99942   
## season15     3.196e-05  8.104e-03   0.004  0.99686   
## season16     5.805e-05  8.105e-03   0.007  0.99430   
## season17     8.414e-05  8.105e-03   0.010  0.99174   
## season18     4.436e-04  8.106e-03   0.055  0.95647   
## season19     1.363e-04  8.107e-03   0.017  0.98662   
## season20     4.957e-04  8.108e-03   0.061  0.95137   
## season21     1.885e-04  8.109e-03   0.023  0.98150   
## season22     5.479e-04  8.110e-03   0.068  0.94627   
## season23     1.257e-02  8.111e-03   1.550  0.12422   
## season24     2.668e-04  8.112e-03   0.033  0.97383   
## season25     6.262e-04  8.113e-03   0.077  0.93863   
## season26     3.190e-04  8.114e-03   0.039  0.96872   
## season27     3.451e-04  8.115e-03   0.043  0.96617   
## season28     3.712e-04  8.116e-03   0.046  0.96362   
## season29     1.340e-02  8.117e-03   1.650  0.10199   
## season30     4.233e-04  8.119e-03   0.052  0.95852   
## season31     4.494e-04  8.120e-03   0.055  0.95597   
## season32     4.755e-04  8.121e-03   0.059  0.95343   
## season33     5.016e-04  8.123e-03   0.062  0.95088   
## season34     5.277e-04  8.124e-03   0.065  0.94834   
## season35     5.538e-04  8.126e-03   0.068  0.94580   
## season36     5.799e-04  8.127e-03   0.071  0.94326   
## season37     6.060e-04  8.129e-03   0.075  0.94072   
## season38     6.321e-04  8.130e-03   0.078  0.93819   
## season39     6.582e-04  8.132e-03   0.081  0.93566   
## season40     6.843e-04  8.134e-03   0.084  0.93313   
## season41     7.103e-04  8.136e-03   0.087  0.93060   
## season42     7.364e-04  8.137e-03   0.090  0.92807   
## season43     2.376e-02  8.139e-03   2.919  0.00433 **
## season44     1.112e-02  8.141e-03   1.366  0.17496   
## season45     1.381e-02  8.143e-03   1.696  0.09291 . 
## season46     1.351e-02  8.145e-03   1.658  0.10038   
## season47     8.669e-04  8.147e-03   0.106  0.91547   
## season48     8.930e-04  8.149e-03   0.110  0.91296   
## season49     1.252e-03  8.151e-03   0.154  0.87820   
## season50     7.668e-04  9.066e-03   0.085  0.93277   
## season51     2.929e-04  9.067e-03   0.032  0.97430   
## season52     7.819e-03  9.068e-03   0.862  0.39062   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.00992 on 100 degrees of freedom
## Multiple R-squared:  0.3855, Adjusted R-squared:  0.06597 
## F-statistic: 1.206 on 52 and 100 DF,  p-value: 0.21
#create the forecast for submeter in the Kitchen. Forecast ahead 20 time periods 

forecastfitKitchen <- forecast(fitKitchen, h=20)
plot(forecastfitKitchen)

#create submeter Kitchen forecast with confidence levels 80 and 90

forecastfitKitchen2 <- forecast(fitKitchen, h=20, level = c(80, 90))
plot(forecastfitKitchen2, ylim = c(0, 0.04), ylab = "KwH", xlab = "Time")

#ecompose submeter Kitchen into trend, seasonal and remainder

decomposedForecast <- decompose(tsKitchen)

#plot decomposed sub-meter 1 

plot(decomposedForecast, col = "red")

#statistic summary

summary(decomposedForecast)

output

##          Length Class  Mode     
## x        153    ts     numeric  
## seasonal 153    ts     numeric  
## trend    153    ts     numeric  
## random   153    ts     numeric  
## figure    52    -none- numeric  
## type       1    -none- character
#seasonal adjusting sub-meter 1 by subtracting the seasonal component & plot

tsAdjusted <- tsKitchen - decomposedForecast$seasonal
autoplot(tsAdjusted, col = 'red', xlab = "Time", ylab = "KwH", main = "Kitchen")

#now usging Holt Winters Exponential Smoothing

tsHW <- HoltWinters(tsAdjusted, beta = FALSE, gamma = FALSE)
plot(tsHW, ylim = c(-0.035, 0.045))

#forecast Holt Winters

tsHWforecast <- forecast(tsHW, h=25)
plot(tsHWforecast, ylim = c(0, 0.04), ylab= "KwH", xlab = "Time - Kitchen")

#forecast HoltWinters with diminished confidence levels

tsHWforecast2 <- forecast(tsHW, h = 25, level = c(10, 25))
plot(tsHWforecast2, ylim = c(0, 0.04), ylab = "KwH", xlab = "Time - Kitchen", start(2010))

LAUNDRY-ROOM

#subset to one observation per day on 

weekly_07_09_laundry <- filter(yr_07_08_09, Weekday == 1 & 
                              Hour == 20 & Minute == 1)

#TS object with submeter from Kitchen

tsLaundry <- ts(weekly_07_09_laundry$Laundry_room, frequency=52, start = c(2007, 1))

#ploting submeter Kitchen with autoplot - add labels, color

autoplot(tsLaundry, ts.colour = 'red', xlab = "Time", ylab = "KwH", main = "Laundry_room")

#trying other plotting package

plot.ts(tsLaundry)

#linear model
fitLaundry <- tslm(tsLaundry ~ trend + season) 
summary(fitLaundry)

output

## 
## Call:
## tslm(formula = tsLaundry ~ trend + season)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.015298 -0.001965  0.000000  0.001333  0.025667 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  2.336e-03  4.451e-03   0.525   0.6009  
## trend       -3.778e-05  1.464e-05  -2.582   0.0113 *
## season2     -2.955e-04  6.198e-03  -0.048   0.9621  
## season3     -2.578e-04  6.198e-03  -0.042   0.9669  
## season4      7.800e-04  6.199e-03   0.126   0.9001  
## season5      1.215e-02  6.199e-03   1.960   0.0527 .
## season6      5.223e-04  6.199e-03   0.084   0.9330  
## season7      2.267e-04  6.199e-03   0.037   0.9709  
## season8      5.978e-04  6.199e-03   0.096   0.9234  
## season9      2.969e-03  6.200e-03   0.479   0.6331  
## season10     6.732e-06  6.200e-03   0.001   0.9991  
## season11     4.452e-05  6.200e-03   0.007   0.9943  
## season12     7.490e-04  6.201e-03   0.121   0.9041  
## season13     1.079e-02  6.201e-03   1.740   0.0850 .
## season14     1.491e-03  6.201e-03   0.240   0.8105  
## season15     5.290e-04  6.202e-03   0.085   0.9322  
## season16     5.668e-04  6.202e-03   0.091   0.9274  
## season17     1.271e-03  6.203e-03   0.205   0.8380  
## season18     6.423e-04  6.203e-03   0.104   0.9177  
## season19     1.680e-03  6.204e-03   0.271   0.7871  
## season20     1.005e-02  6.205e-03   1.620   0.1084  
## season21     7.557e-04  6.205e-03   0.122   0.9033  
## season22     1.379e-02  6.206e-03   2.223   0.0285 *
## season23     1.216e-02  6.207e-03   1.960   0.0528 .
## season24     8.691e-04  6.208e-03   0.140   0.8889  
## season25     9.068e-04  6.208e-03   0.146   0.8842  
## season26     1.028e-02  6.209e-03   1.655   0.1010  
## season27     9.824e-04  6.210e-03   0.158   0.8746  
## season28     1.020e-03  6.211e-03   0.164   0.8699  
## season29     7.246e-04  6.212e-03   0.117   0.9074  
## season30     1.096e-03  6.213e-03   0.176   0.8604  
## season31     9.800e-03  6.214e-03   1.577   0.1179  
## season32     1.171e-03  6.215e-03   0.188   0.8509  
## season33     2.209e-03  6.216e-03   0.355   0.7230  
## season34     1.580e-03  6.217e-03   0.254   0.7999  
## season35     2.285e-03  6.218e-03   0.367   0.7141  
## season36     1.656e-03  6.220e-03   0.266   0.7906  
## season37     1.027e-03  6.221e-03   0.165   0.8692  
## season38     1.731e-03  6.222e-03   0.278   0.7814  
## season39     1.769e-03  6.223e-03   0.284   0.7768  
## season40     1.140e-03  6.225e-03   0.183   0.8550  
## season41     1.845e-03  6.226e-03   0.296   0.7676  
## season42     2.883e-03  6.227e-03   0.463   0.6445  
## season43     8.587e-03  6.229e-03   1.379   0.1711  
## season44     2.291e-03  6.230e-03   0.368   0.7138  
## season45     7.329e-03  6.232e-03   1.176   0.2423  
## season46     2.367e-03  6.233e-03   0.380   0.7049  
## season47     1.407e-02  6.235e-03   2.257   0.0262 *
## season48     1.776e-03  6.236e-03   0.285   0.7764  
## season49     5.480e-03  6.238e-03   0.879   0.3818  
## season50     5.357e-04  6.938e-03   0.077   0.9386  
## season51     5.735e-04  6.939e-03   0.083   0.9343  
## season52     2.111e-03  6.940e-03   0.304   0.7616  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.007591 on 100 degrees of freedom
## Multiple R-squared:  0.3273, Adjusted R-squared:  -0.02244 
## F-statistic: 0.9358 on 52 and 100 DF,  p-value: 0.5975
#create the forecast for submeter in the Kitchen. Forecast ahead 20 time periods 

forecastfitLaundry <- forecast(fitLaundry, h=20)
plot(forecastfitKitchen)

#create submeter Kitchen forecast with confidence levels 80 and 90

forecastfitLaundry2 <- forecast(fitLaundry, h=20, level = c(80, 90))
plot(forecastfitLaundry2, ylim = c(0, 0.04), ylab = "KwH", xlab = "Time")

#ecompose submeter Kitchen into trend, seasonal and remainder

decomposedForecastLaundry <- decompose(tsLaundry)

#plot decomposed sub-meter 1 

plot(decomposedForecastLaundry, col = "red")

#statistic summary

summary(decomposedForecastLaundry)

output

##          Length Class  Mode     
## x        153    ts     numeric  
## seasonal 153    ts     numeric  
## trend    153    ts     numeric  
## random   153    ts     numeric  
## figure    52    -none- numeric  
## type       1    -none- character
#seasonal adjusting sub-meter 1 by subtracting the seasonal component & plot

tsAdjustedLaundry <- tsLaundry - decomposedForecastLaundry$seasonal
autoplot(tsAdjustedLaundry, col = 'red', xlab = "Time", ylab = "KwH", main = "Laundry_Room")

#now usging Holt Winters Exponential Smoothing

tsHWLaundry <- HoltWinters(tsAdjustedLaundry, beta = FALSE, gamma = FALSE)
plot(tsHW, ylim = c(-0.035, 0.045))

#forecast Holt Winters

tsHWforecastLaundry <- forecast(tsHWLaundry, h=25)
plot(tsHWforecast, ylim = c(0, 0.04), ylab= "KwH", xlab = "Time - Kitchen")

#forecast HoltWinters with diminished confidence levels

tsHWforecastLaundry2 <- forecast(tsHWLaundry, h = 25, level = c(10, 25))
plot(tsHWforecastLaundry2, ylim = c(0, 0.04), ylab = "KwH", xlab = "Time - Laundry_Room", start(2010))

WATER HEATER

#subset to one observation per day on 

weekly_07_09_WaterH <- filter(yr_07_08_09, Weekday == 1 & 
                              Hour == 20 & Minute == 1)

#TS object with submeter from Kitchen

tsWaterH <- ts(weekly_07_09_WaterH$Water_heater, frequency=52, start = c(2007, 1))

#ploting submeter Kitchen with autoplot - add labels, color

autoplot(tsWaterH, ts.colour = 'red', xlab = "Time", ylab = "KwH", main = "Water_heater and AC")

#trying other plotting package

plot.ts(tsWaterH)

#linear model
fitWaterH <- tslm(tsWaterH ~ trend + season) 
summary(fitWaterH)

output

## 
## Call:
## tslm(formula = tsWaterH ~ trend + season)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0127169 -0.0052831 -0.0003836  0.0052831  0.0127169 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  9.930e-03  4.695e-03   2.115   0.0369 *
## trend        2.020e-05  1.544e-05   1.308   0.1937  
## season2      3.131e-04  6.537e-03   0.048   0.9619  
## season3     -5.707e-03  6.538e-03  -0.873   0.3848  
## season4      5.606e-03  6.538e-03   0.858   0.3932  
## season5     -5.747e-03  6.538e-03  -0.879   0.3814  
## season6      5.566e-03  6.538e-03   0.851   0.3966  
## season7     -1.112e-02  6.538e-03  -1.701   0.0921 .
## season8     -1.114e-02  6.538e-03  -1.704   0.0915 .
## season9      1.718e-04  6.539e-03   0.026   0.9791  
## season10     6.485e-03  6.539e-03   0.992   0.3237  
## season11     3.131e-03  6.539e-03   0.479   0.6331  
## season12    -5.222e-03  6.540e-03  -0.799   0.4265  
## season13    -5.242e-03  6.540e-03  -0.802   0.4247  
## season14    -1.060e-02  6.541e-03  -1.620   0.1084  
## season15    -1.062e-02  6.541e-03  -1.623   0.1077  
## season16    -7.636e-03  6.542e-03  -1.167   0.2458  
## season17    -8.990e-03  6.542e-03  -1.374   0.1725  
## season18    -1.068e-02  6.543e-03  -1.632   0.1059  
## season19    -4.697e-03  6.543e-03  -0.718   0.4745  
## season20    -5.384e-03  6.544e-03  -0.823   0.4126  
## season21    -7.061e-05  6.545e-03  -0.011   0.9914  
## season22    -5.091e-03  6.545e-03  -0.778   0.4385  
## season23     9.889e-03  6.546e-03   1.511   0.1340  
## season24    -5.131e-03  6.547e-03  -0.784   0.4350  
## season25    -5.151e-03  6.548e-03  -0.787   0.4333  
## season26    -7.505e-03  6.549e-03  -1.146   0.2545  
## season27    -1.119e-02  6.550e-03  -1.709   0.0906 .
## season28    -5.212e-03  6.551e-03  -0.796   0.4281  
## season29    -1.123e-02  6.552e-03  -1.714   0.0896 .
## season30    -5.252e-03  6.553e-03  -0.802   0.4247  
## season31    -5.273e-03  6.554e-03  -0.805   0.4230  
## season32    -4.959e-03  6.555e-03  -0.757   0.4511  
## season33     1.020e-03  6.556e-03   0.156   0.8766  
## season34    -5.333e-03  6.557e-03  -0.813   0.4180  
## season35     6.466e-04  6.558e-03   0.099   0.9217  
## season36    -5.040e-03  6.560e-03  -0.768   0.4441  
## season37    -9.060e-03  6.561e-03  -1.381   0.1704  
## season38    -1.108e-02  6.562e-03  -1.689   0.0944 .
## season39     2.325e-04  6.564e-03   0.035   0.9718  
## season40    -5.788e-03  6.565e-03  -0.882   0.3801  
## season41    -1.181e-02  6.567e-03  -1.798   0.0752 .
## season42    -1.614e-04  6.568e-03  -0.025   0.9804  
## season43    -5.150e-04  6.570e-03  -0.078   0.9377  
## season44    -5.868e-03  6.571e-03  -0.893   0.3740  
## season45    -5.889e-03  6.573e-03  -0.896   0.3724  
## season46    -2.422e-04  6.574e-03  -0.037   0.9707  
## season47     5.738e-03  6.576e-03   0.873   0.3850  
## season48    -6.283e-03  6.578e-03  -0.955   0.3418  
## season49     3.054e-05  6.579e-03   0.005   0.9963  
## season50    -2.965e-03  7.318e-03  -0.405   0.6863  
## season51    -1.148e-02  7.318e-03  -1.569   0.1197  
## season52     5.495e-03  7.319e-03   0.751   0.4546  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.008007 on 100 degrees of freedom
## Multiple R-squared:  0.4152, Adjusted R-squared:  0.1111 
## F-statistic: 1.365 on 52 and 100 DF,  p-value: 0.09211
#create the forecast for submeter in the Kitchen. Forecast ahead 20 time periods 

forecastfitWaterH <- forecast(fitWaterH, h=20)
plot(forecastfitWaterH)

#create submeter Kitchen forecast with confidence levels 80 and 90

forecastfitWaterH2 <- forecast(fitWaterH, h=20, level = c(80, 90))
plot(forecastfitWaterH2, ylim = c(0, 0.04), ylab = "KwH", xlab = "Time")

#ecompose submeter Kitchen into trend, seasonal and remainder

decomposedForecastWaterH <- decompose(tsWaterH)

#plot decomposed sub-meter 1 

plot(decomposedForecastWaterH, col = "red")

#statistic summary

summary(decomposedForecastWaterH)

output

##          Length Class  Mode     
## x        153    ts     numeric  
## seasonal 153    ts     numeric  
## trend    153    ts     numeric  
## random   153    ts     numeric  
## figure    52    -none- numeric  
## type       1    -none- character
#seasonal adjusting sub-meter 1 by subtracting the seasonal component & plot

tsAdjustedWaterH <- tsWaterH - decomposedForecastWaterH$seasonal
autoplot(tsAdjustedWaterH, col = 'red', xlab = "Time", ylab = "KwH", main = "Water_heater and AC")

#now usging Holt Winters Exponential Smoothing

tsHWWaterH <- HoltWinters(tsAdjustedWaterH, beta = FALSE, gamma = FALSE)
plot(tsWaterH, ylim = c(-0.035, 0.045))

#forecast Holt Winters

tsHWforecastWaterH <- forecast(tsHWWaterH, h=25)
plot(tsHWforecastWaterH, ylim = c(0, 0.04), ylab= "KwH", xlab = "Time - Water_heater and AC")

#forecast HoltWinters with diminished confidence levels

tsHWforecastWaterH2 <- forecast(tsHWWaterH, h = 25, level = c(10, 25))
plot(tsHWforecastWaterH2, ylim = c(0, 0.04), ylab = "KwH", xlab = "Time - Water_heater and AC", start(2010))

REST OF THE HOUSE

#subset to one observation per day on 

weekly_07_09_House <- filter(yr_07_08_09, Weekday == 1 & 
                              Hour == 20 & Minute == 1)

#TS object with submeter from Kitchen

tsHouse <- ts(weekly_07_09_House$Rest_house, frequency=52, start = c(2007, 1))

#ploting submeter Kitchen with autoplot - add labels, color

autoplot(tsHouse, ts.colour = 'red', xlab = "Time", ylab = "KwH", main = "Rest of the House")

#trying other plotting package

plot.ts(tsHouse)

#linear model
fitHouse <- tslm(tsHouse ~ trend + season) 
summary(fitHouse)

output

## 
## Call:
## tslm(formula = tsHouse ~ trend + season)
## 
## Residuals:
##        Min         1Q     Median         3Q        Max 
## -0.0292864 -0.0043802 -0.0002864  0.0047136  0.0240000 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.377e-02  6.582e-03   9.688 4.79e-16 ***
## trend       -5.218e-05  2.164e-05  -2.411 0.017725 *  
## season2     -2.595e-02  9.166e-03  -2.831 0.005612 ** 
## season3     -1.856e-02  9.166e-03  -2.025 0.045519 *  
## season4     -1.951e-02  9.166e-03  -2.129 0.035752 *  
## season5     -3.479e-02  9.166e-03  -3.796 0.000253 ***
## season6     -3.241e-02  9.167e-03  -3.535 0.000619 ***
## season7     -3.635e-02  9.167e-03  -3.966 0.000138 ***
## season8     -4.063e-02  9.167e-03  -4.433 2.39e-05 ***
## season9     -2.858e-02  9.168e-03  -3.118 0.002380 ** 
## season10    -3.320e-02  9.168e-03  -3.621 0.000463 ***
## season11    -3.948e-02  9.168e-03  -4.306 3.89e-05 ***
## season12    -5.243e-02  9.169e-03  -5.718 1.12e-07 ***
## season13    -4.437e-02  9.170e-03  -4.839 4.74e-06 ***
## season14    -5.599e-02  9.170e-03  -6.105 1.96e-08 ***
## season15    -5.527e-02  9.171e-03  -6.027 2.81e-08 ***
## season16    -4.755e-02  9.172e-03  -5.185 1.13e-06 ***
## season17    -4.650e-02  9.172e-03  -5.069 1.84e-06 ***
## season18    -5.078e-02  9.173e-03  -5.536 2.50e-07 ***
## season19    -4.973e-02  9.174e-03  -5.420 4.13e-07 ***
## season20    -4.834e-02  9.175e-03  -5.269 7.91e-07 ***
## season21    -4.896e-02  9.176e-03  -5.335 5.96e-07 ***
## season22    -5.557e-02  9.177e-03  -6.055 2.47e-08 ***
## season23    -4.785e-02  9.178e-03  -5.214 1.00e-06 ***
## season24    -5.480e-02  9.179e-03  -5.970 3.64e-08 ***
## season25    -5.441e-02  9.181e-03  -5.927 4.41e-08 ***
## season26    -5.403e-02  9.182e-03  -5.884 5.34e-08 ***
## season27    -5.598e-02  9.183e-03  -6.096 2.06e-08 ***
## season28    -5.592e-02  9.184e-03  -6.089 2.12e-08 ***
## season29    -5.287e-02  9.186e-03  -5.756 9.49e-08 ***
## season30    -5.249e-02  9.187e-03  -5.713 1.15e-07 ***
## season31    -5.177e-02  9.189e-03  -5.634 1.63e-07 ***
## season32    -5.538e-02  9.190e-03  -6.026 2.82e-08 ***
## season33    -5.200e-02  9.192e-03  -5.657 1.47e-07 ***
## season34    -5.294e-02  9.194e-03  -5.759 9.36e-08 ***
## season35    -4.756e-02  9.195e-03  -5.172 1.19e-06 ***
## season36    -5.184e-02  9.197e-03  -5.637 1.61e-07 ***
## season37    -5.079e-02  9.199e-03  -5.521 2.67e-07 ***
## season38    -5.340e-02  9.201e-03  -5.804 7.65e-08 ***
## season39    -5.068e-02  9.203e-03  -5.507 2.83e-07 ***
## season40    -4.130e-02  9.205e-03  -4.487 1.94e-05 ***
## season41    -4.791e-02  9.207e-03  -5.204 1.04e-06 ***
## season42    -3.053e-02  9.209e-03  -3.315 0.001277 ** 
## season43    -2.681e-02  9.211e-03  -2.911 0.004448 ** 
## season44    -2.276e-02  9.213e-03  -2.470 0.015204 *  
## season45    -2.037e-02  9.215e-03  -2.211 0.029347 *  
## season46    -1.432e-02  9.217e-03  -1.553 0.123488    
## season47    -1.560e-02  9.220e-03  -1.692 0.093767 .  
## season48    -3.288e-02  9.222e-03  -3.565 0.000559 ***
## season49    -2.016e-02  9.225e-03  -2.186 0.031174 *  
## season50    -3.280e-02  1.026e-02  -3.197 0.001860 ** 
## season51    -1.475e-02  1.026e-02  -1.437 0.153767    
## season52    -1.070e-02  1.026e-02  -1.042 0.299818    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.01123 on 100 degrees of freedom
## Multiple R-squared:  0.7265, Adjusted R-squared:  0.5843 
## F-statistic: 5.109 on 52 and 100 DF,  p-value: 1.528e-12
#create the forecast for submeter in the Kitchen. Forecast ahead 20 time periods 

forecastfitHouse <- forecast(fitHouse, h=20)
plot(forecastfitHouse)

#create submeter Kitchen forecast with confidence levels 80 and 90

forecastfitHouse2 <- forecast(fitHouse, h=20, level = c(80, 90))
plot(forecastfitHouse2, ylim = c(0, 0.04), ylab = "KwH", xlab = "Time")

#ecompose submeter Kitchen into trend, seasonal and remainder

decomposedForecastHouse <- decompose(tsHouse)

#plot decomposed sub-meter 1 

plot(decomposedForecastHouse, col = "red")

#statistic summary

summary(decomposedForecastHouse)

output

##          Length Class  Mode     
## x        153    ts     numeric  
## seasonal 153    ts     numeric  
## trend    153    ts     numeric  
## random   153    ts     numeric  
## figure    52    -none- numeric  
## type       1    -none- character
#seasonal adjusting sub-meter 1 by subtracting the seasonal component & plot

tsAdjustedHouse <- tsHouse - decomposedForecastHouse$seasonal
autoplot(tsAdjustedHouse, col = 'red', xlab = "Time", ylab = "KwH", main = "Rest of the House")

#now usging Holt Winters Exponential Smoothing

tsHWHouse <- HoltWinters(tsAdjustedHouse, beta = FALSE, gamma = FALSE)
plot(tsHouse, ylim = c(-0.035, 0.045))

#forecast Holt Winters

tsHWforecastHouse <- forecast(tsHWHouse, h=25)
plot(tsHWforecastHouse, ylim = c(0, 0.04), ylab= "KwH", xlab = "Time - Rest of the House")

#forecast HoltWinters with diminished confidence levels

tsHWforecastHouse2 <- forecast(tsHWHouse, h = 25, level = c(10, 25))
plot(tsHWforecastHouse2, ylim = c(0, 0.04), ylab = "KwH", xlab = "Time - Rest of the House", start(2010))

#sesh info
sessionInfo()

output

## R version 4.0.0 (2020-04-24)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 19041)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
## [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
## [5] LC_TIME=German_Germany.1252    
## 
## attached base packages:
## [1] grid      stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] forecast_8.12    ggfortify_0.4.10 lubridate_1.7.8  dplyr_0.8.5     
##  [5] magrittr_1.5     knitr_1.28       plotly_4.9.2.1   ggplot2_3.3.0   
##  [9] RMySQL_0.10.20   DBI_1.1.0       
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.4.6       lattice_0.20-41    tidyr_1.0.2        zoo_1.8-7         
##  [5] assertthat_0.2.1   digest_0.6.25      lmtest_0.9-37      R6_2.4.1          
##  [9] evaluate_0.14      httr_1.4.1         highr_0.8          pillar_1.4.4      
## [13] rlang_0.4.6        lazyeval_0.2.2     curl_4.3           data.table_1.12.8 
## [17] fracdiff_1.5-1     TTR_0.23-6         rmarkdown_2.1      labeling_0.3      
## [21] stringr_1.4.0      htmlwidgets_1.5.1  munsell_0.5.0      compiler_4.0.0    
## [25] xfun_0.13          pkgconfig_2.0.3    urca_1.3-0         htmltools_0.4.0   
## [29] nnet_7.3-13        tidyselect_1.0.0   tibble_3.0.0       gridExtra_2.3     
## [33] quadprog_1.5-8     fansi_0.4.1        viridisLite_0.3.0  crayon_1.3.4      
## [37] withr_2.1.2        nlme_3.1-147       jsonlite_1.6.1     gtable_0.3.0      
## [41] lifecycle_0.2.0    scales_1.1.1       quantmod_0.4.17    cli_2.0.2         
## [45] stringi_1.4.6      farver_2.0.3       tseries_0.10-47    timeDate_3043.102 
## [49] ellipsis_0.3.0     xts_0.12-0         generics_0.0.2     vctrs_0.2.4       
## [53] RColorBrewer_1.1-2 tools_4.0.0        glue_1.4.0         purrr_0.3.4       
## [57] crosstalk_1.1.0.1  parallel_4.0.0     yaml_2.2.1         colorspace_1.4-1